package org.manon.json.custom;

import java.io.IOException;
import java.io.OutputStream;

import junit.framework.Assert;

import org.manon.json.JSONConstants;
import org.manon.json.SerializerProvider;
import org.manon.json.filter.Filter;


public final class CustomCollectionChildSerializer extends CustomSerializer<CustomCollectionChild> {

	public static final byte[] NAME = "name-custon-ser".getBytes();
	
	private final SerializerProvider _provider;
	
	public CustomCollectionChildSerializer(SerializerProvider provider) {
		_provider = provider;
	}

	/**
	 * @see org.manon.json.io.Serializer#serialize(java.io.OutputStream, java.lang.Object, org.manon.json.filter.Filter)
	 */
	public void serialize(OutputStream os, CustomCollectionChild pojo, Filter filter) throws IOException {

		// no filter
		
		os.write(JSONConstants.START_OBJECT,0,1);
		
		if (pojo.getName() != null) {
			writeString(os, false, NAME, pojo.getName());
		}
		
		os.write(JSONConstants.END_OBJECT,0,1);
		
		// default serializer for CustomCollectionChild is generated.
		Assert.assertNotSame(this.getClass(), _provider.getSerialiser(CustomCollectionChild.class).getClass());
	}

}